local bofangjian = fk.CreateSkill {
    name = "bofangjian",
    tags = {}, -- 普通技能，可选触发
}

Fk:loadTranslationTable{
    ["bofangjian"] = "放箭",
    [":bofangjian"] = "当你受到伤害后，你可以失去1点体力并发动〖四世〗并翻面。若你已翻面，则翻回正面。",
    ["$bofangjian1"] = "攻灭白马，覆夷黑山，千里之地，其唯我独尊。",
    ["$bofangjian2"] = "平冀并幽，连青统畿，纵横南北，不知败绩何味。",
    ["#bofangjian-trigger"]="是否发动四世？",
}

bofangjian:addEffect(fk.Damaged, {
    anim_type = "offensive",
    can_trigger = function(self, event, target, player, data)
        return target == player and 
               player:hasSkill(bofangjian.name) and 
               data.damage > 0
    end,
    
    on_cost = function(self, event, target, player, data)
        local room = player.room
        return room:askToSkillInvoke(player, {
            skill_name = bofangjian.name,
            prompt = "#bofangjian-trigger",
        })
    end,
    
    on_use = function(self, event, target, player, data)
        local room = player.room
        
        -- 触发技能动画
        room:notifySkillInvoked(player, bofangjian.name)
        
        -- 失去体力
        room:loseHp(player, 1, bofangjian.name)
        if player.dead then return end
        
        -- 发动四世
        local bosishi = Fk.skills["bosishi"] 
        if bosishi then
            bosishi:doCost(event, target, player, data)
        else
            -- 移除或修正日志调用（原错误行）
            -- room:writeToConsole("Error: 未找到四世技能（bosishi）", player)
            room:printToConsole("Error: 未找到四世技能（bosishi）", player) -- 假设正确方法为 printToConsole
        end
        
        -- 翻面逻辑
        player:turnOver() 
    end,
})

return bofangjian
